#include "MainWindow.h"

MainWindow::MainWindow(QWidget* parent):
	QMainWindow(parent)
{
	initMenuToolbar();
	initVtkWidget();
	initSignals();
}

MainWindow::~MainWindow()
{}

void MainWindow::initMenuToolbar()
{
	setWindowTitle("OCCTTutorial");
	setWindowIcon(QIcon(":/icons/icons/3dModel.png"));

	tb_view = new QToolBar(this);
	//tb_view->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
	addToolBar(tb_view);
	act_hideAll = new QAction(QIcon(":/icons/icons/hideAll.png") , "hideAll" , this);
	act_hide = new QAction(QIcon(":/icons/icons/hide.png") , "hide" , this);
	act_fitAll = new QAction(QIcon(":/icons/icons/view-fullscreen.svg"),"fitAll",this);
	act_axo = new QAction(QIcon(":/icons/icons/view-axonometric.svg"),"axo",this);
	act_top = new QAction(QIcon(":/icons/icons/view-top.svg"),"top",this);
	act_buttom = new QAction(QIcon(":/icons/icons/view-bottom.svg"),"buttom",this);
	act_left = new QAction(QIcon(":/icons/icons/view-left.svg"),"left",this);
	act_right = new QAction(QIcon(":/icons/icons/view-right.svg"),"right",this);
	act_front = new QAction(QIcon(":/icons/icons/view-front.svg"),"front",this);
	act_back = new QAction(QIcon(":/icons/icons/view-rear.svg"),"back",this);
	act_shade = new QAction(QIcon(":/icons/icons/DrawStyleShaded.svg"),"shade",this);
	act_wireframe = new QAction(QIcon(":/icons/icons/DrawStyleWireFrame.svg"),"wireframe",this);
	act_test = new QAction(QIcon(":/icons/icons/utilities-terminal.svg"),"test",this);

	tb_view->addActions({act_hideAll,act_hide,act_fitAll,act_axo,
		act_top,act_buttom,act_left,act_right,act_front,act_back});
	tb_view->addSeparator();
	tb_view->addActions({act_shade,act_wireframe});
	tb_view->addSeparator();
	tb_view->addActions({act_test});
}

void MainWindow::initVtkWidget()
{
	wid_vtk = new MVtkWidget(this);
	setCentralWidget(wid_vtk);
}

void MainWindow::initSignals()
{
	connect(act_hideAll,&QAction::triggered,wid_vtk,&MVtkWidget::removeAll);
	connect(act_fitAll,&QAction::triggered,wid_vtk,&MVtkWidget::fitAll);
	connect(act_axo,&QAction::triggered,wid_vtk,&MVtkWidget::ViewAXO);
	connect(act_top,&QAction::triggered,wid_vtk,&MVtkWidget::ViewNegativeZ);
	connect(act_buttom,&QAction::triggered,wid_vtk,&MVtkWidget::ViewPositiveZ);
	connect(act_left,&QAction::triggered,wid_vtk,&MVtkWidget::ViewNegativeX);
	connect(act_right,&QAction::triggered,wid_vtk,&MVtkWidget::ViewPositiveX);
	connect(act_front,&QAction::triggered,wid_vtk,&MVtkWidget::ViewNegativeY);
	connect(act_back,&QAction::triggered,wid_vtk,&MVtkWidget::ViewPositiveY);

	connect(act_test,&QAction::triggered,this,&MainWindow::test);
}

void MainWindow::test()
{
	BRepPrimAPI_MakeBox mkBox(gp_Ax2(gp_Pnt(100, 100, 0), gp_Dir(0,0,1)), 50.,40.,30);
	TopoDS_Shape shape0 = mkBox.Shape();
	TopoDS_Compound shape = MakeBottle();
	wid_vtk->disPlayOCC(shape);
	wid_vtk->disPlayOCC(shape0);
	wid_vtk->fitAll();
}